home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-09-24 | 10.2 KB | 393 lines | [TEXT/CWIE] |
- void LoadImages(void);
- void CopyPixels(Rect,Rect);
- void DrawFinal(void);
- void DrawBackground(void);
- void setupGWorld(void);
- void DrawPlayers(int drawState, Boolean soundPlayed);
-
- CGrafPtr origPort;
- GDHandle origDevice;
-
- GWorldPtr myOffGWorld;
- PixMapHandle offPixMapHandle;
- Rect gWorldRect;
-
- GWorldPtr compGWorld;
- PixMapHandle offCompPixMapHandle;
-
- GWorldPtr parallaxWorld;
- PixMapHandle parallaxPixMapHandle;
-
- PicHandle gBackgroundPic;
-
-
- typedef struct player
- {
- int score;
- int state;
- char name[8];
- long lastAction;
- }player;
-
- player playerOne;
- player playerTwo;
-
- player **pl1info;
- player **pl2info;
-
-
- WindowPtr gScoreWindow;
- WindowPtr gWindowTwo;
- WindowPtr gScreenWindow;
- extern WindowPtr gMainWindow;
- Rect gOffScreenWindowRect;
- Rect gWindowTwoRect;
- extern Boolean gatesBlood;
- extern Boolean aronBlood;
-
- int gParallaxOnePosition,
- gParallaxTwoPosition;
-
- Handle soundOne;
-
- void LoadImages (void)
- {
- PicHandle playerOnePict;
- PicHandle playerTwoPict;
- PicHandle parallaxOnePic;
- PicHandle parallaxTwoPic;
-
- Rect ImageOneRect;
- Rect ImageTwoRect;
- Rect parallaxOneRect;
- Rect parallaxTwoRect;
-
- SetGWorld(myOffGWorld,nil);
-
- SetRect(&ImageOneRect,0,0,640,210);
- SetRect(&ImageTwoRect,0,210,640,420);
- SetRect(¶llaxOneRect,0,0,801,210);
- SetRect(¶llaxTwoRect,0,210,801,420);
-
- if(aronBlood)
- playerOnePict=GetPicture(668);
- else
- playerOnePict=GetPicture(667);
-
- if(gatesBlood)
- playerTwoPict=GetPicture(14);
- else
- playerTwoPict=GetPicture(13);
-
-
- parallaxOnePic=GetPicture(251);
- parallaxTwoPic=GetPicture(250);
-
- DrawPicture(playerOnePict,&ImageOneRect);
- DrawPicture(playerTwoPict,&ImageTwoRect);
-
- SetGWorld(parallaxWorld,nil);
- DrawPicture(parallaxOnePic,¶llaxOneRect);
- DrawPicture(parallaxTwoPic,¶llaxTwoRect);
- }
-
- void CopyPixels(Rect sourceRect,Rect destRect)
- {
-
- RGBColor background;
-
- background.red=0;
- background.blue=65535;
- background.green=65535;
- RGBBackColor(&background);
-
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- }
-
- void DrawFinal(void)
- {
- Rect compRect,
- outRect;
- RGBColor background;
-
- background.red=0;
- background.blue=65535;
- background.green=65535;
- RGBBackColor(&background);
-
- SetRect(&compRect,0,0,320,210);
- SetRect(&outRect,0,0,320,210);
-
- SetGWorld(origPort,origDevice);
- CopyBits (&((GrafPort*)compGWorld)->portBits,&((GrafPort*)gWindowTwo)->portBits,
- &compRect, &outRect, transparent, nil );
- }
-
- void DrawBackground(void)
- {
- Rect parallaxOneRect,
- parallaxTwoRect,
- backgroundRect,
- destRect,
- sourceRect;
- RGBColor background;
-
-
- background.red=0;
- background.blue=65535;
- background.green=65535;
- RGBBackColor(&background);
-
-
- SetRect(&backgroundRect,0,0,320,210);
- SetRect(¶llaxOneRect,0,0,320,210);
- SetRect(¶llaxTwoRect,0,210,320,420);
-
-
- SetGWorld(compGWorld,nil);
-
- //Calculate Positions and Draw Images to Offscreen World
- if (gParallaxOnePosition < 801-320)
- {
- parallaxOneRect.left = parallaxOneRect.left+gParallaxOnePosition;
- parallaxOneRect.right = parallaxOneRect.right+gParallaxOnePosition;
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- ¶llaxOneRect, &backgroundRect, transparent, nil );
- }
- else
- {
- sourceRect.left=gParallaxOnePosition;
- sourceRect.right=801;
- sourceRect.top=0;
- sourceRect.bottom=210;
- destRect.left=0;
- destRect.right=(801-gParallaxOnePosition);
- destRect.top=0;
- destRect.bottom=210;
-
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- sourceRect.left=0;
- sourceRect.right=(320-801+gParallaxOnePosition);
- sourceRect.top=0;
- sourceRect.bottom=210;
- destRect.left=(801-gParallaxOnePosition);
- destRect.right=(320);
- destRect.top=0;
- destRect.bottom=210;
-
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- }
-
- if (gParallaxTwoPosition < 801-320)
- {
- parallaxTwoRect.left = parallaxTwoRect.left+gParallaxTwoPosition;
- parallaxTwoRect.right = parallaxTwoRect.right+gParallaxTwoPosition;
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- ¶llaxTwoRect, &backgroundRect, transparent, nil );
- }
- else
- {
- sourceRect.left=gParallaxTwoPosition;
- sourceRect.right=801;
- sourceRect.top=210;
- sourceRect.bottom=420;
- destRect.left=0;
- destRect.right=(801-gParallaxTwoPosition);
- destRect.top=0;
- destRect.bottom=210;
-
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- sourceRect.left=0;
- sourceRect.right=(320-801+gParallaxTwoPosition);
- sourceRect.top=210;
- sourceRect.bottom=420;
- destRect.left=(801-gParallaxTwoPosition);
- destRect.right=(320);
- destRect.top=0;
- destRect.bottom=210;
-
- CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- }
-
-
- //move Parallax Positions
- gParallaxOnePosition = gParallaxOnePosition + 3;
- gParallaxTwoPosition = gParallaxTwoPosition + 8;
-
- if (gParallaxOnePosition > 801)
- gParallaxOnePosition = (gParallaxOnePosition - 801);
-
- if (gParallaxTwoPosition > 801)
- gParallaxTwoPosition = (gParallaxTwoPosition - 801);
- }
-
- void setupGWorld(void)
- {
- Rect compGWorldRect;
- Rect parallaxWorldRect;
-
- SetRect(&gWorldRect,0,0,640,420);
- SetRect(&compGWorldRect,0,0,360,240);
- SetRect(¶llaxWorldRect,0,0,801,420);
-
- GetGWorld(&origPort,&origDevice);
-
- NewGWorld(&myOffGWorld,0,&gWorldRect,nil,nil,0);
- SetGWorld(myOffGWorld,nil);
- offPixMapHandle = GetGWorldPixMap(myOffGWorld);
- LockPixels(offPixMapHandle);
- EraseRect(&myOffGWorld->portRect);
-
- NewGWorld(&compGWorld,0,&compGWorldRect,nil,nil,0);
- SetGWorld(compGWorld,nil);
- offPixMapHandle = GetGWorldPixMap(compGWorld);
- LockPixels(offCompPixMapHandle);
- EraseRect(&compGWorld->portRect);
-
- NewGWorld(¶llaxWorld,0,¶llaxWorldRect,nil,nil,0);
- SetGWorld(parallaxWorld,nil);
- offPixMapHandle = GetGWorldPixMap(parallaxWorld);
- LockPixels(parallaxPixMapHandle);
- EraseRect(¶llaxWorld->portRect);
- }
-
- void DrawPlayers(int drawState, Boolean soundPlayed)
- {
- Rect sourceRect,
- destRect;
- RGBColor background;
-
- background.red=0;
- background.blue=65535;
- background.green=65535;
- RGBBackColor(&background);
-
-
- switch(drawState)
- {
- case 1:
- //player One Hits
- SetRect(&sourceRect,0,210,320,420);
- SetRect(&destRect,0,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- //Player Two Gets Hit
- SetRect(&sourceRect,160,0,320,210);
- SetRect(&destRect,160,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- break;
- case 2:
- // Player Two Duck
- SetRect(&sourceRect,0,0,160,127);
- SetRect(&destRect,160,83,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- //player One Hits
- SetRect(&sourceRect,0,210,320,420);
- SetRect(&destRect,0,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 3:
- //Player One Gets Hit
- SetRect(&sourceRect,320,210,480,420);
- SetRect(&destRect,0,0,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- //player Two Hits
- SetRect(&sourceRect,320,0,640,210);
- SetRect(&destRect,0,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 4:
- // Player One Normal
- SetRect(&sourceRect,480,210,640,420);
- SetRect(&destRect,0,0,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- // Player Two Normal
- SetRect(&sourceRect,0,0,160,210);
- SetRect(&destRect,160,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 5:
- // Player Two Duck
- SetRect(&sourceRect,0,0,160,127);
- SetRect(&destRect,160,83,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- // Player One Normal
- SetRect(&sourceRect,480,210,640,420);
- SetRect(&destRect,0,0,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 6:
- // Player One Duck
- SetRect(&sourceRect,480,210,640,337);
- SetRect(&destRect,0,83,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- //player Two Hits
- SetRect(&sourceRect,320,0,640,210);
- SetRect(&destRect,0,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 7:
- // Player One Duck
- SetRect(&sourceRect,480,210,640,337);
- SetRect(&destRect,0,83,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- // Player Two Normal
- SetRect(&sourceRect,0,0,160,210);
- SetRect(&destRect,160,0,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- break;
- case 8:
- // Player One Duck
- SetRect(&sourceRect,480,210,640,337);
- SetRect(&destRect,0,83,160,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
- // Player Two Duck
- SetRect(&sourceRect,0,0,160,127);
- SetRect(&destRect,160,83,320,210);
- SetGWorld(compGWorld,nil);
- CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits,
- &sourceRect, &destRect, transparent, nil );
-
- break;
- }
- }